package com.ple.app.importdata;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.graphics.PointF;
import android.os.Bundle;
import android.app.Activity;
import android.os.Handler;
import android.os.Message;
import android.widget.ImageView;

import com.ple.app.jzsf.R;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;



public class InfomationActivity extends Activity {

    /**
     *缩放定义
     */
    private  int mMode;
    private int maxscale=3;
    private float minscal= (float) 0.5;
    final private  int DRAGMODE=1;
    final private int ZOOMMODE=2;
    private PointF mStarpt=new PointF();
    private float mStartdis;
    private PointF mMidpt=new PointF();
    private Matrix mMatrix=new Matrix();
    private Matrix mCurrMatrix=new Matrix();
    //
    private ImageView imageView;
     Handler handle=new Handler(){
         @Override
         public void handleMessage(Message msg) {
            // super.handleMessage(msg);
             switch(msg.what){
                 case 0:
                     Bitmap bmp= (Bitmap) msg.obj;
                     imageView.setImageBitmap(bmp);
                     break;
             }

         }
     };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_infomation);
        imageView= (ImageView) findViewById(R.id.information_picture);

       // imageView.setImageBitmap(bb);
        new Thread(new Runnable() {
            @Override
            public void run() {
                Bitmap bb=gethttpbiatmap("http://pic.qiantucdn.com/58pic/14/11/74/10d58PICKsq_1024.jpg");
                Message msg=new Message();
                msg.obj=bb;
                msg.what=0;
                handle.sendMessage(msg);
            }
        }).start();
        /**
         * 自由缩放
         */
        Image_opreation image_opreation=new Image_opreation(imageView);


    }//oncreat
/**
 * 获得图片
 */
    private byte[] downimage() throws IOException {
        ByteArrayOutputStream byteArrayOutputStream=new ByteArrayOutputStream();
        URL url=new URL("http://pic22.nipic.com/20120722/9656370_212838673000_2.jpg");
        HttpURLConnection connection= (HttpURLConnection) url.openConnection();//拿到http对象.
        connection.setConnectTimeout(5000);//设置超时
        connection.setDoInput(true);//获取服务器的响应内容
        connection.setRequestMethod("GET");//请求方式
        connection.connect();
        int code=connection.getResponseCode();
        if(code==200){//获取成功
            //拿到输入流，用于读取响应的内容
            InputStream is=connection.getInputStream();
            byte[] data=new byte[1024];
            int len;
            while ((len=is.read(data))!=-1){
                byteArrayOutputStream.write(data,0,len);
            }//while
           return byteArrayOutputStream.toByteArray();
        }//if
        else{
        return null;}
    }
    private Bitmap gethttpbiatmap(String str){
        URL url=null;Bitmap bitmap=null;
        try {
             url=new URL(str);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        try {
            HttpURLConnection connection= (HttpURLConnection) url.openConnection();

            connection.setConnectTimeout(5000);//设置超时
            connection.setDoInput(true);//获取服务器的响应内容
            //connection.setRequestMethod("GET");//请求方式
            connection.connect();
            InputStream is=connection.getInputStream();
            bitmap=BitmapFactory.decodeStream(is);
            is.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return bitmap;
    }


}
